home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 079 / sharedlib / protect.i.orig < prev    next >
Text File  |  1995-03-13  |  1KB  |  53 lines

  1. ;; Protect.i    Copyright 1987 by James M Synge
  2. ;;
  3. ;; An assembly macro for protecting registers.
  4. ;; Not for the weak of heart.
  5.  
  6.     macro    protect
  7.  
  8.     if    NARG <> 2
  9.     fail        ; Must specify the number of args!
  10.     mexit
  11.     endc
  12.  
  13.     iflt    \2
  14.     fail        ; Negative number of args!
  15.     mexit
  16.     endc
  17.  
  18. ; Until a bug fix arrives for the assembler so that the \0
  19. ; macro works, we must assume the argument size is 4 bytes.
  20.  
  21. \@elementsize    set 4
  22. \@bytes        set \@elementsize * \2
  23. \@offset    set \@bytes + (AztecBugSize * 4)
  24.  
  25.     movem.l    AztecBugList,-(sp)    ; Save some regs
  26.  
  27.     ; Push the argument(s).  We'll use D0 as our scratch
  28.     ; register since it is free for that use according
  29.     ; to the register convention.
  30.     
  31.     ifne    \2    ; If there are any arguments
  32.  
  33.     moveq    #\2,d0    ; Number of arguments to move
  34. \@loop    move.l    \@offset(sp),-(sp)    ; Push an arg
  35.     dbeq    d0,\@loop        ; Loop again?
  36.     
  37.     endc
  38.  
  39.     jsr    \1    ; Call the C routine
  40.  
  41.     ifne    \2        ; Pop any arguments
  42.     ifge    8 - \@bytes    ; Can we use addq.l?
  43.     addq.l    #\@bytes,sp    ; Yup!
  44.     else
  45.     lea    \@bytes(sp),sp    ; Otherwise use lea
  46.     endc
  47.     endc
  48.  
  49.     movem.l    (sp)+,AztecBugList    ; Restore regs
  50.     rts        ; And return
  51.  
  52.     endm    ; End of the protect macro
  53.